package com.qlm.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.qlm.interceptor.AdminOperate2Interceptor;
import com.qlm.interceptor.AdminOperateInterceptor;
import com.qlm.interceptor.AuthInterceptor;
import com.qlm.service.IQrcodeAddService;
import com.qlm.service.impl.QrcodeAddServiceImpl;

@Before(AuthInterceptor.class)
public class QrcodeAddController extends Controller{
	
	private static final Logger logger = LoggerFactory.getLogger(QrcodeAddController.class);
	
	private IQrcodeAddService qrcodeAddService = enhance(QrcodeAddServiceImpl.class);
	
	/**
	 * 进入产码页面
	 */
	@Before({AdminOperateInterceptor.class,AdminOperate2Interceptor.class})
	public void qrcode(){
		List<String> urlList = qrcodeAddService.getPropertiesUrl();
		setAttr("urlList", urlList);
		render("/page/qrcode.jsp");
	}
	
	/**
	 * 产码
	 */
	@Before({AdminOperateInterceptor.class,AdminOperate2Interceptor.class})
	public void qrCodeAdd(){
		String url = getPara("url");
		Integer number = getParaToInt("number");
		Integer addNum = getParaToInt("addNum");
		String id = getPara("id");
		String code = getPara("code");
		String money = getPara("money");
		String filePath = getSession().getServletContext().getRealPath("/") + "QRCode";
		String zipFilePath = qrcodeAddService.getZipFilePath(url, number, filePath,addNum,id,code,money);		
		renderText(zipFilePath);
	}
	
	/**
	 * 获取产码数量
	 */
	public void getProgress(){
		String id = getPara("id");
		Integer progress = qrcodeAddService.getProgress(id);		
		renderText(progress+"");
	}
		
	
	
	
}
